package com.huawei.petSystemdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.widget.Button;
import android.widget.Checkable;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huawei.petSystemdemo.ui.my.MyFragment;
import com.huawei.petSystemdemo.utils.MyRequest;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class personal_page extends AppCompatActivity {
    EditText info_name;
    EditText info_qq;
    EditText info_tel;
    EditText info_sign;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal_page);
//
//        System.out.println("ggggggggggggggggggggggggggg");
//        info_name = findViewById(R.id.info_name);
//        info_qq = findViewById(R.id.info_qq);
//        info_tel = findViewById(R.id.info_tel);
//        info_sign = findViewById(R.id.info_sign);
//
//        TextView info_modify = findViewById(R.id.info_modify);
//
//
//        info_modify.setOnClickListener(v->{
//            System.out.println("999");
//            if(ChickInput()){
//                System.out.println("111111111111");
//                Map<String,Object> requestBody = new HashMap<>();
//                requestBody.put("username",info_name.getText().toString());
//                requestBody.put("password",info_qq.getText().toString());
//                requestBody.put("username",info_tel.getText().toString());
//                requestBody.put("password",info_sign.getText().toString());
//                MyRequest.post("/user/infomodify", requestBody, new Callback() {
//                    @Override
//                    public void onFailure(@NotNull Call call, @NotNull IOException e) {
//                        System.out.println("222222222222");
//                        Looper.prepare();
//                        System.out.println("连接服务器失败!");
//                        Toast.makeText(personal_page.this,"连接服务器失败!",Toast.LENGTH_SHORT).show();
//                        Looper.loop();
//                    }
//
//                    @Override
//                    public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
//                        System.out.println("3333333333333");
//                        String json = response.body().string();
//                        JSONObject jsonObject = JSON.parseObject(json);
//                        int statusCode = jsonObject.getInteger("statusCode");
//                    }
//                });
//            }
//
//        });
    }

    public void onClick (android.view.View back){
        Intent intent = new Intent(this, MyFragment.class);//界面跳转
        startActivity(intent);
    }

    public boolean ChickInput(){
        String name = info_name.getText().toString();
        String tel = info_tel.getText().toString();
        String sign = info_sign.getText().toString();
        String qq = info_qq.getText().toString();
        //trim() 方法用于删除字符串的头尾空白符
        if(name.equals("")) {
            Toast.makeText(personal_page.this,"网名不能为空!",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(tel.equals("")) {
            Toast.makeText(personal_page.this,"电话不能为空!",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(sign.equals("")) {
            Toast.makeText(personal_page.this,"个性签名不能为空!",Toast.LENGTH_SHORT).show();
            return false;
        }
        if(qq.equals("")) {
            Toast.makeText(personal_page.this,"qq不能为空!",Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }
}